#include "GapStateBase.h"
#include "GapGenerator.h"
#include "Trace.h"

namespace tsc
{
namespace mgw
{

using namespace tsc::common;

/*******************************************************************************
 *
 * Constructor
 *
 ******************************************************************************/
GapStateBase::GapStateBase(const char* name) :
    StateBase(name)
{

} // GapStateBase::GapStateBase

/*******************************************************************************
 *
 * Destructor
 *
 ******************************************************************************/
GapStateBase::~GapStateBase()
{

} // GapStateBase::~GapStateBase


//===================================================================
bool
GapStateBase::txEnabled() const
{
    return false;
}

//===================================================================
void
GapStateBase::handleEvent(
    common::Generator*  generator,
    common::EventData*& eventData)
{
    if (!eventData)
    {
        TRACE(1, "EventData to handle is NULL");
        return;
    }

    switch (eventData->sigNo())
    {
    case GAP_CONNECT_CFM:
    {
        handleEventGapConnectCfm(
            static_cast<GapGenerator*>(generator),
            static_cast<GapEventConnectCfm*>(eventData),
            eventData);
    }
    break;

    case GAP_CONNECT_REJ:
    {
        handleEventGapConnectRej(
            static_cast<GapGenerator*>(generator),
            static_cast<GapEventConnectRej*>(eventData),
            eventData);
    }
    break;

    case GAP_T709_EXPIRED:
    {
        handleEventGapT709Expired(
            static_cast<GapGenerator*>(generator),
            static_cast<GapEventT709Expired*>(eventData),
            eventData);
    }
    break;

    case GAP_T711_EXPIRED:
    {
        handleEventGapT711Expired(
            static_cast<GapGenerator*>(generator),
            static_cast<GapEventT711Expired*>(eventData),
            eventData);
    }
    break;

    case GAP_ECHO_REQUEST:
    {
        handleEventGapEchoReq(
            static_cast<GapGenerator*>(generator),
            static_cast<GapEventEchoReq*>(eventData),
            eventData);
    }
    break;

    case GAP_MEDIA_BEARER_SETUP_REQ:
    {
        handleEventGapMediaBearerSetupReq(
            static_cast<GapGenerator*>(generator),
            static_cast<GapEventMediaBearerSetupReq*>(eventData),
            eventData);
    }
    break;

    case GAP_MEDIA_BEARER_RELEASE:
    {
        handleEventGapMediaBearerRelease(
            static_cast<GapGenerator*>(generator),
            static_cast<GapEventMediaBearerRelease*>(eventData),
            eventData);
    }
    break;

    default:
        TRACE_ERROR(STR("Event:sigNo=0x%x not handled in switch",
                        eventData->sigNo()));
        EventData::deleteEvent(eventData);
    }
}

//===================================================================
void
GapStateBase::handleEventGapConnectCfm(
    GapGenerator* gapGen,
    GapEventConnectCfm* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event GapEventConnectCfm not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void
GapStateBase::handleEventGapConnectRej(
    GapGenerator*          gapGen,
    GapEventConnectRej* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event GapEventConnectRej not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}


//===================================================================
void
GapStateBase::handleEventGapT709Expired(
    GapGenerator* gapGen,
    GapEventT709Expired* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event GapEventT709Expired not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void
GapStateBase::handleEventGapT711Expired(
    GapGenerator* gapGen,
    GapEventT711Expired* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event GapEventT711Expired not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void
GapStateBase::handleEventGapEchoReq(
    GapGenerator* gapGen,
    GapEventEchoReq* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event GapEventEchoReq not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void
GapStateBase::handleEventGapMediaBearerSetupReq(
    GapGenerator* gapGen,
    GapEventMediaBearerSetupReq* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event GapEventMediaBearerSetupReq not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void
GapStateBase::handleEventGapMediaBearerRelease(
    GapGenerator* gapGen,
    GapEventMediaBearerRelease* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event GapEventMediaBearerRelease not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

} // namespace sgw
} // namespace tsc
